TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file TextFormat.php

Documentation is available at TextFormat.php

  1. <?php
  2.  
  3.  /**
  4.  * TextFormat class
  5.  *
  6.  * Description: Chart data export to Text
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage exports
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16.  class TextFormat extends DataExportFormat {
  17.  
  18.     public static function textDelimiter(){
  19.         return Language::getString("TabDelimiter");
  20.     }
  21.  
  22.     // Interceptors
  23.     function __get( $property ) {
  24.       $method ="get{$property}";
  25.       if ( method_exists( $this, $method ) ) {
  26.         return $this->$method();
  27.       }
  28.     }
  29.  
  30.     function __set ( $property,$value ) {
  31.       $method ="set{$property}";
  32.       if ( method_exists( $this, $method ) ) {
  33.         return $this->$method($value);
  34.       }
  35.     }
  36.  
  37.     public function TextFormat($c) {
  38.         parent::DataExportFormat($c);
  39.         
  40.         $this->setFileExtension("txt");
  41.     }
  42.  
  43.     protected function getContent() {
  44.         $this->prepare();
  45.         (string)$tmpResult="";
  46.  
  47.         $tmpResult=$tmpResult . ($this->getIncludeSeriesTitle() ?
  48.                          ((string)$this->headerTitle() . (string)$this->getTextLineSeparator()) :
  49.                          "");
  50.         $tmpResult=$tmpResult . ($this->getIncludeHeader() ? ((string)$this->header() . (string)$this->getTextLineSeparator()) :
  51.                          "");
  52.  
  53.         $tmpResult= $tmpResult . (parent::getContent() . $this->getTextLineSeparator());
  54.  
  55.         return (string)$tmpResult;
  56.     }
  57.  
  58.     public function getFilterFiles() {
  59.         return Language::getString("TextFilter");
  60.     }
  61.  
  62.     private function headerSeriesTitle($aSeries) {
  63.         $tmpResult="";
  64.  
  65.         if ($this->hasLabels) {
  66.             $tmpResult=$tmpResult . $aSeries->toString() . self::textDelimiter();
  67.         }
  68.  
  69.         if ($this->hasNoMandatory && !$this->hasLabels) {
  70.             $tmpResult=$tmpResult . $aSeries->toString() . self::textDelimiter();
  71.         }
  72.  
  73.         if (!$this->hasLabels && !$this->hasNoMandatory) {
  74.             $tmpResult=$tmpResult . $aSeries->toString() . self::textDelimiter();
  75.         } else {
  76.             $tmpResult=$tmpResult . self::textDelimiter();
  77.         }
  78.  
  79.         for ( $t = 2; $t < sizeof($aSeries->getValuesLists()); $t++) {
  80.             $tmpResult=$tmpResult . self::textDelimiter();
  81.         }
  82.  
  83.         return $tmpResult;
  84.     }
  85.  
  86.  
  87.     private function headerSeries($aSeries) {
  88.          $tmpResult = "";
  89.  
  90.         if ($this->hasLabels) {
  91.             $tmpResult=$tmpResult . Language::getString("Text");
  92.             $tmpResult=$tmpResult . self::textDelimiter();
  93.         }
  94.  
  95.         if ($this->hasNoMandatory) {
  96.             $tmpResult=$tmpResult . $aSeries->getNotMandatory()->getName();
  97.             $tmpResult=$tmpResult . self::textDelimiter();
  98.         }
  99.  
  100.         $tmpResult=$tmpResult . $aSeries->getMandatory()->getName();
  101.  
  102.         for ( $t = 2; $t < sizeof($aSeries->getValuesLists()); $t++) {
  103.             $tmpResult=$tmpResult . (self::textDelimiter() . $aSeries->getValueList($t)->getName());
  104.         }
  105.  
  106.         return $tmpResult;
  107.     }
  108.  
  109.     private function headerTitle() {
  110.         //CDI - each column should be headed by the name of the valuelist
  111.         //new header line with Series.ToString() added.
  112.          $tmpResult="";
  113.  
  114.         if ($this->getIncludeIndex()) {
  115.             $tmpResult=$tmpResult . self::textDelimiter();
  116.         }
  117.  
  118.         if ($this->series != null) {
  119.             $tmpResult=$tmpResult . $this->headerSeriesTitle($this->series);
  120.         } else {
  121.             for ( $t = 0; $t < $this->chart->getSeriesCount(); $t++) {
  122.                 $tmpResult=$tmpResult . $this->headerSeriesTitle($this->chart->getSeries($t));
  123.             }
  124.         }
  125.  
  126.         $length = strlen($tmpResult);
  127.  
  128.         $tmpResult=substr($tmpResult,0,$length-1);
  129.  
  130.         return $tmpResult;
  131.     }
  132.  
  133.     private function header() {
  134.         $tmpResult = "";
  135.  
  136.         $tmpResult=$tmpResult . ($this->getIncludeIndex() ? /* TODO $this->Language->getString(*/"Index"/*)*/ : "");
  137.  
  138.         if (strlen($tmpResult) != 0) {
  139.             $tmpResult=$tmpResult . self::textDelimiter();
  140.         }
  141.  
  142.         if ($this->series != null) {
  143.             $tmpResult=$tmpResult . $this->headerSeries($this->series);
  144.         } else
  145.         if ($this->chart->getSeriesCount() > 0) {
  146.  
  147.             $tmpResult=$tmpResult . $this->headerSeries($this->chart->getSeries(0));
  148.  
  149.             for ( $t = 1; $t < $this->chart->getSeriesCount(); $t++) {
  150.                 $tmpResult=$tmpResult . (self::textDelimiter() . $this->headerSeries($this->chart->getSeries($t)));
  151.             }
  152.         }
  153.  
  154.         return $tmpResult;
  155.     }
  156.  
  157.     protected function pointToString($index) {
  158.          $result = $this->getIncludeIndex() ? (string)$index : "";
  159.  
  160.         // Export Series data
  161.         if ($this->series != null) {
  162.             $result= $result . self::textDelimiter()+$this->doSeries($index, $this->series);
  163.         } else {
  164.             for ( $t = 0; $t < $this->chart->getSeriesCount(); $t++) {
  165.                 $result= $result . self::textDelimiter() . $this->doSeries($index, $this->chart->getSeries($t));
  166.             }
  167.         }
  168.  
  169.         if(substr($result,0,strlen(self::textDelimiter()))==self::textDelimiter()) {
  170.             $result= str_replace(self::textDelimiter(), "",$result);
  171.         }
  172.  
  173.         return (string)$result;
  174.     }
  175.  
  176.     private function add($st, $result) {
  177.         return $result . self::textDelimiter() . $st;
  178.     }
  179.  
  180.     private function doSeries($index, $aSeries) {
  181.  
  182.          $result="";
  183.         //tmpNum++;
  184.  
  185.         /* the point Label text, if exists */
  186.         if ( /*($this->tmpNum==1)&&*/($this->hasLabels)) { //$this->CDI $this->let'    for  $the $this->series
  187.             if ($aSeries->getCount() > $index) {
  188.                 $labels=$aSeries->getLabels();
  189.                 (string)$result=$this->add($labels[$index], $result);
  190.             } else {
  191.                 (string)$result=$this->add("", $result);
  192.             }
  193.         }
  194.  
  195.         /* the "X" point value, if exists */
  196.         //add(FloatToStr(ASeries.NotMandatoryValueList.Value[Index]));
  197.         if ($this->hasNoMandatory) {
  198.             if ($aSeries->getCount() > $index) {
  199.                 (string)$result=$this->add($aSeries->getNotMandatory()->getValue($index),
  200.                     $result);
  201.             } else {
  202.                 (string)$result=$this->add("", $result);
  203.             }
  204.         }
  205.  
  206.         /* the "Y" point value */
  207.         if ($aSeries->getCount() > $index) {
  208.             (string)$result=$this->add($aSeries->getMandatory()->getValue($index), $result);
  209.         } else {
  210.             (string)$result=$this->add("", $result);
  211.         }
  212.  
  213.         /* write the rest of values (always) */
  214.         for ( $tt = 2; $tt < sizeof($aSeries->getValuesLists()); $tt++) {
  215.  
  216.             if ($aSeries->getCount() > $index) {
  217.                 $result = $result . self::textDelimiter() .
  218.                         $aSeries->getValueList($tt)->getValue($index);
  219.             } else {
  220.                 $result = $result . self::textDelimiter() . "";
  221.             }
  222.         }
  223.  
  224.         if(substr($result,0,strlen(self::textDelimiter()))==self::textDelimiter()) {
  225.             $result= str_replace(self::textDelimiter(), "",$result);
  226.         }
  227.  
  228.         return (string)$result;
  229.     }
  230. }
  231. ?>

Documentation generated on Wed, 16 Jun 2010 12:08:43 +0200 by phpDocumentor 1.4.1